//
//  PlayeMediaViewController.m
//  GC_OC
//
//  Created by wlf on 2022/5/12.
//

#import "PlayeMediaViewController.h"
#import "ICMusicPlayModel.h"
#import "UIImage+ImageEffects.h"
#import "PlayVoiceSubtitleView.h"
#import "ZFSliderView.h"
#import "Common.h"
#import "XHComMacro.h"
#import "PlayMulitplePopView.h"
#import "ICMusicPlayListVC.h"
#import "ICMusicPlayManager.h"
#import "PlayCountDownView.h"
#import "PlayListView.h"
#import "HSVideoPlayViewController.h"
#import "PlayLoadingView.h"
#import "WPFLyricView.h"
#import "ObjectAFNetWorking.h"
#import "cache.h"
#import "LoginViewController.h"
@interface PlayeMediaViewController ()<ZFSliderViewDelegate, WPFLyricViewDelegate,UIDocumentInteractionControllerDelegate>
@property (nonatomic, strong) UIButton *contentBtn;
@property (nonatomic, strong) UIButton *audioBtn;
@property (nonatomic, strong) UIButton *videoBtn;
@property (nonatomic, strong) UIButton *zimuBtn;
@property (nonatomic, strong) UIView *tabLineView;
@property (nonatomic, strong) UIStackView *stackView;
@property (nonatomic, strong) UIView *tagView;
@property (nonatomic, strong) UILabel *titleLabelView;
@property (nonatomic, strong) UIView *middleBackView;
@property (nonatomic, strong)PlayVoiceSubtitleView* playsubtitleView;
@property (nonatomic, strong) UITextView *contentTextView;
//底部视图
@property(nonatomic, strong) UIView *bottomOprateView;
@property(nonatomic, strong) UIImageView *playBackImgV;

//进度视图
@property(nonatomic, strong) UIView *progressOprateView;

@property(nonatomic, strong) ZFSliderView *sliderView;

@property(nonatomic, strong) UILabel *videoTimeLabel;
@property(nonatomic, strong) UILabel *beginTime;                    //起始时间
@property(nonatomic, strong) UILabel *endTime;

@property(nonatomic, strong) UIButton *timeBtn;

@property(nonatomic, strong) UIButton *formerBtn;                   //上一首
@property(nonatomic, strong) UIButton *playBtn;                     //播放、暂停
@property(nonatomic, strong) UIButton *nextBtn;                     //下一首
@property(nonatomic, strong) UIButton *cycleBtn;
@property(nonatomic, strong) UIButton *likeBtn;

@property(nonatomic, strong)NSTimer *progressTimer;                  //处理进度
@property(nonatomic, strong) UIView *timeListMaskView;
//时间选择视图
@property(nonatomic, strong) UIView *timeSelectView;
@property (nonatomic, strong) PlayCountDownView *countDownView;
@property(nonatomic, strong) PlayLoadingView *loadingView;
@property (nonatomic, strong) ObjectAFNetWorking* objectAFN;

@property (nonatomic, strong) NSArray* audioListArray;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;
@property(nonatomic, strong) UIButton *lastTabBtn;                   //上一首
@property(nonatomic, strong) PlayListView *listView;

@property(nonatomic, copy) NSString *countDownType;
@property (nonatomic,strong)UIDocumentInteractionController *documentInteraction;
@property (nonatomic,strong)UIButton *backBtn;
@end

@implementation PlayeMediaViewController{
    NSArray *_btnNameArray;         //底部功能按钮集合
    NSArray *_btnselectArray;       //底部功能选中状态按钮集合
    NSArray *_titleNameArray;       //底部功能按钮标题
    NSMutableArray *_bottomBtns;
    NSArray *_timeListNameArray;            //时间选择视图选择项
    NSMutableArray *_timeButtonArray;
    NSMutableArray *_timeImageViewArray;
    SlidleStatue slideStatue;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.objectAFN = [[ObjectAFNetWorking alloc]init];
    _timeListNameArray = @[@"不开启",@"10分钟后",@"20分钟后",@"30分钟后",@"60分钟后",@"90分钟后",@"播完当前音频后"];
    [self setSubUI];

    [ICMusicPlayManager sharedManager].playerLoadStateChanged = ^(id  _Nonnull asset, ICPlayerLoadState loadState) {
        if (loadState == ICPlayerLoadStateStalled || loadState == ICPlayerLoadStatePrepare) {
            [self.loadingView startAnimation:self.playBtn imageName:@"LoginLoading"];
            self.playBtn.hidden = YES;
            self.loadingView.hidden = NO;
        }else if (loadState == ICPlayerLoadStatePlayable){
            
            [self.loadingView endAnimation];
            self.playBtn.hidden = NO;
            self.loadingView.hidden = YES;

        }
        
    };

    [self.playsubtitleView refreshUrl:self.currentModel.srt andFileId:[NSString stringWithFormat:@"%@",self.currentModel.id]];
    [self getDataWithID:self.currentModel.id];
    if ([FKCacheTool isLogin]) {
        UserModel *userModel = [Cache shared].userInfo;
        if (userModel) {
            [self getonecollectAction:[Cache shared].userInfo.userinfo.user_id];

        } else {
            NSDictionary *info = [[NSUserDefaults standardUserDefaults] valueForKey:@"bnyt_userInfo"];
            if (info.count != 0) {
                //先加载本地
                UserModel *userModel = [[UserModel alloc] initWithDictionary:info[@"data"] error:nil];
                [Cache shared].userInfo = userModel;
                [self getonecollectAction:userModel.userinfo.id];
            }
        }

    }
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self setNavigationBarHidden];
    [self.navigationController setNavigationBarHidden:YES animated:animated];

}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    _documentInteraction = nil;
}
-(void)setupDocumentInteractionVc{
    NSURL *fileUrl =  [NSURL URLWithString:self.currentModel.file];
//    NSURL *fileUrl = [NSURL fileURLWithPath:self.currentModel.file isDirectory:NO];
    self.documentInteraction = [UIDocumentInteractionController interactionControllerWithURL:fileUrl];
    self.documentInteraction.delegate = self;
    [self.documentInteraction presentPreviewAnimated:YES];
}
#pragma mark -UIDocumentInteractionControllerDelegate
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
{
    return self;
}
- (nullable UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
{
    return self.view;
    
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleDefault;
    
}
- (void)setSubUI{
   
    UIImageView *backgroundImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    backgroundImgV.image = [UIImage imageNamed:@"playerBg"];
    backgroundImgV.userInteractionEnabled = true;
    backgroundImgV.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:backgroundImgV];
//    backgroundImgV.image = [[UIImage imageNamed:@"playerBg"] applyDarkEffect];r
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
    visualView.frame = CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
    visualView.alpha = 0.3;
    [self.view addSubview:visualView];
    
    [self setTopSubUI];
    [self setTopTabbarView];
    [self initMiddleTextView];
    [self setPlayProgress];
    [self initBottomFactView];
//    [self initTimeView];
}
//标题
- (void)setTopSubUI{
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,HY_StatusBar_Height + 4,32,32)];
    backImage.image = [UIImage imageNamed:@"icon_fanhui"];
    [self.view addSubview:backImage];
   
    UIButton *likeBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 16 - 66 - 35, HY_StatusBar_Height + 8, 30, 30)];
    CGFloat maxWidth = SCREEN_WIDTH - 16 - 66 - 35 - 32;
    if (self.currentModel.file.length > 0) {
        UIButton *fileBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 16 - 66, HY_StatusBar_Height + 8, 66, 30)];
        [fileBtn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.25]] forState:UIControlStateNormal];
        fileBtn.layer.cornerRadius = 15;
        fileBtn.layer.masksToBounds = YES;
        [fileBtn setTitle:@" 文件" forState:UIControlStateNormal];
        [fileBtn setTitleColor:[UIColor colorWithHex:@"#0091FF"] forState:UIControlStateNormal];
        [fileBtn setImage:[UIImage imageNamed:@"icon_wenjian"] forState:UIControlStateNormal];
        fileBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [fileBtn addTarget:self action:@selector(setupDocumentInteractionVc) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:fileBtn];
        
       
    }else{
        likeBtn.frame = CGRectMake(SCREEN_WIDTH - 16 - 35, HY_StatusBar_Height + 8, 30, 30);
        maxWidth = SCREEN_WIDTH - 16 - 35 - 32;
    }
   
    [likeBtn setBackgroundImage:[UIImage imageNamed:@"icon_Collect_default"] forState:UIControlStateNormal];
    [likeBtn setBackgroundImage:[UIImage imageNamed:@"icon_Collect_select"] forState:UIControlStateSelected];
    [likeBtn addTarget:self action:@selector(likeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.likeBtn = likeBtn;
    
    [self.view addSubview:likeBtn];
    if ([FKCacheTool isLogin]) {
        self.likeBtn.hidden = NO;
    } else {
        self.likeBtn.hidden = YES;
    }
    
    NSArray *titleArray = [self.currentModel.media_class_name componentsSeparatedByString:@"|"];
    if (titleArray.count >= 2) {
        
        CGFloat textWidth=[GC_OCTool getMaxWidthForLabel:titleArray[0] andFont:[UIFont systemFontOfSize: 16] andHeight:22 maxWidth:maxWidth] + 1;
        [self setTextLabel:titleArray[0] frame:CGRectMake(32,HY_StatusBar_Height + 4,maxWidth,20) font:[UIFont systemFontOfSize: 16]];
       self.subTitleLabel = [self setTextLabel:titleArray[1] frame:CGRectMake(32 ,HY_StatusBar_Height + 25,maxWidth,11) font:[UIFont systemFontOfSize: 10]];
    }else if(titleArray.count == 1){
        CGFloat textWidth = [GC_OCTool getMaxWidthForLabel:titleArray[0] andFont:[UIFont systemFontOfSize: 16] andHeight:22 maxWidth:maxWidth] + 1;

        [self setTextLabel:titleArray[0] frame:CGRectMake(32,HY_StatusBar_Height + 3,maxWidth,20) font:[UIFont systemFontOfSize: 16]];
        self.subTitleLabel =  [self setTextLabel:@"" frame:CGRectMake(32,HY_StatusBar_Height + 15,maxWidth,11) font:[UIFont systemFontOfSize: 10]];
    }else{
        
        
        [self setTextLabel:@"" frame:CGRectMake(32,HY_StatusBar_Height + 4,maxWidth,20) font:[UIFont systemFontOfSize: 16]];
        self.subTitleLabel = [self setTextLabel:@"" frame:CGRectMake(32 + 0,HY_StatusBar_Height + 15,maxWidth,11) font:[UIFont systemFontOfSize: 10]];
    }
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, HY_StatusBar_Height + 4, maxWidth + 15, 32)];
    [self.view addSubview:backBtn];
    [backBtn  addTarget:self action:@selector(_leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.backBtn = backBtn;
    
}
//顶部切换
- (void)setTopTabbarView{
    for (UIView *view in self.stackView.arrangedSubviews) {
        [self.stackView  removeArrangedSubview:view];
    }
    [self.stackView removeFromSuperview];
    self.stackView = nil;
    
    [self.tabLineView removeFromSuperview];
    [self.view  addSubview:self.stackView];
    self.stackView.top = HY_StatusBar_Height + 40;
//    if (self.currentModel.introduce) {
//        self.contentBtn = [self setTabbarButton:@"内容"];
//        [self.stackView addArrangedSubview:self.contentBtn];
//    }
    if (self.currentModel.video_url.length > 0 ||
        self.currentModel.srt.length > 0) {
        self.audioBtn = [self setTabbarButton:@"音频"];
        [self.stackView addArrangedSubview:self.audioBtn];
        [self.audioBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.view addSubview:self.tabLineView];
       
    }
    
    if (self.currentModel.video_url.length > 0) {
        self.videoBtn = [self setTabbarButton:@"视频"];
        [self.stackView addArrangedSubview:self.videoBtn];
        
    }
    
    if (self.currentModel.srt.length > 0) {
        self.zimuBtn = [self setTabbarButton:@"字幕"];
        [self.stackView addArrangedSubview:self.zimuBtn];
    }
    self.tabLineView.y = CGRectGetMaxY(self.stackView.frame) + 4;
//    self.tabLineView.centerX = self.stackView.centerX;
    
    if (self.stackView.arrangedSubviews.count <= 1) {
        [self.stackView removeFromSuperview];
        self.tagView.y = CGRectGetMaxY(self.subTitleLabel.frame) + 42;
        self.titleLabelView.frame = CGRectMake(26,CGRectGetMaxY(self.subTitleLabel.frame) + 34,SCREEN_WIDTH - 144,27);
        self.titleLabelView.text = self.currentModel.name;
        self.titleLabelView.centerY = self.tagView.centerY;
        self.tabLineView.hidden = YES;
    }else{
        self.tagView.y = CGRectGetMaxY(self.stackView.frame) + 20;
        self.titleLabelView.frame = CGRectMake(26,124,SCREEN_WIDTH - 144,27);
        self.titleLabelView.text = self.currentModel.name;
        self.titleLabelView.centerY = self.tagView.centerY;
        
        if (self.contentBtn) {
                self.tabLineView.centerX = ((SCREEN_WIDTH - 154) / self.stackView.arrangedSubviews.count) * 1.5 + 77;
        }else{
            self.tabLineView.centerX = ((SCREEN_WIDTH - 154) / self.stackView.arrangedSubviews.count) * 0.5 + 77;

        }
    }
}
- (UIButton *)setTabbarButton:(NSString *)buttonText {
    UIButton *button = [[UIButton alloc] init];
    [button setTitle:buttonText forState:UIControlStateNormal];
  
    button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [button addTarget:self action:@selector(tabbarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor colorWithHex:@"#BBC4DA"] forState:UIControlStateNormal];
    return button;
}

- (UILabel *)setTextLabel:(NSString *)text frame:(CGRect)frame font:(UIFont *)font{
    UILabel *label = [[UILabel alloc] init];
    label.frame = frame;
    [self.view addSubview:label];
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text attributes: @{NSFontAttributeName: font,NSForegroundColorAttributeName: [UIColor whiteColor]}];
    label.attributedText = string;
    label.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:label];
    return label;
}
//中间部分
- (void)initMiddleTextView{
    if (self.middleBackView != nil) {
        for (UIView *view in self.middleBackView.subviews) {
            [view removeFromSuperview];
        }
        [self.middleBackView removeFromSuperview];
    }
    CGFloat  middleHeight = SCREEN_HEIGHT - (CGRectGetMaxY(self.titleLabelView.frame) + 20 + 65 + 206 + HY_BottomWhiteBar_Height);
    self.middleBackView=[[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabelView.frame) + 20, SCREEN_WIDTH, middleHeight)];
//    self.middleBackView.backgroundColor =  [UIColor greenColor];
    [self.view addSubview:self.middleBackView];
    
    
    CGFloat tipWidth=[GC_OCTool getWidthForLabel:@"相关: " andFont:TitleFontSize(14) andHeight:hig(100)];
    NSArray* lableArray = self.currentModel.lable;
    NSInteger labelCount = lableArray.count > 6 ? 6: lableArray.count;
    CGFloat lableX = tipWidth + 20;
    CGFloat lableMaxY = labelCount > 3 ? 64 : 25;
    
    NSArray* array = self.currentModel.additional;
    NSInteger count = array.count > 6 ? 6: array.count;
    CGFloat fjLabelMaxY = count > 3 ? 64 : 25;
    
    UILabel* fjLabel=[[UILabel alloc]init];
    fjLabel.left = 20;
    fjLabel.top = middleHeight - lableMaxY - 25 - fjLabelMaxY;
    fjLabel.width = 48;
    fjLabel.height = 22;
    fjLabel.text = @"附件: ";
    fjLabel.textColor = [UIColor whiteColor];
    fjLabel.font = TitleFontSize(14);
    [self.middleBackView addSubview:fjLabel];
    CGFloat btnWidth = (SCREEN_WIDTH - 77 - 40 - 24 - 15) / 3.0;
//    CGFloat height = CGRectGetMaxY(self.contentTextView.frame) + 20;
  
    fjLabel.hidden = count ==  0;
//    CGFloat titleMaxY = height;
    for(int i=0;i < count;i++){
        NSDictionary *dict = array[i];
        NSInteger x = i%3;
        NSInteger y = i/3;
        UIButton* btn = [[UIButton alloc] init];
        btn.x = 15 + CGRectGetMaxX(fjLabel.frame) + x * (btnWidth + 12);
        btn.size = CGSizeMake(btnWidth, 25);
        if (count > 3 && i <= 2) {
            btn.bottom = CGRectGetMinY(fjLabel.frame) + 64;
        }else{
            btn.bottom = CGRectGetMinY(fjLabel.frame) + 25;
        }
//        btn.centerY = fjLabel.centerY;
        [btn setTitle:dict[@"title"] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#D8D8D8" alpha:0.14]] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        [btn setBackgroundImage:[UIImage imageWithColor:AppMainColor] forState:UIControlStateHighlighted];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        btn.layer.cornerRadius = 12;
        btn.layer.masksToBounds = YES;
        [self.middleBackView addSubview:btn];
//        titleMaxY = height + y * (25 + 14) + 25;
    }
    
    UILabel* lastLabel=[[UILabel alloc]init];
    lastLabel.hidden = labelCount ==  0;
    lastLabel.left = 20;
    lastLabel.top = middleHeight - lableMaxY;
    lastLabel.width = 48;
    lastLabel.height = 20;
    lastLabel.text = @"相关: ";
    lastLabel.font = TitleFontSize(14);
    lastLabel.textColor = [UIColor whiteColor];
    [self.middleBackView addSubview:lastLabel];
    
    for(int i = 0;i < labelCount; i++){
        NSInteger x=i%3;
        NSInteger y=i/3;
        NSDictionary *dict = lableArray[i];
        NSString *labelStr = dict[@"label"];
        CGFloat lableWidth=[GC_OCTool getWidthForLabel:labelStr andFont:TitleFontSize(12) andHeight:14] + 10;
        lableX = tipWidth + 20 + i * (lableWidth + 10);
        UIButton* btn = [[UIButton alloc]init];
        btn.x = 15 + CGRectGetMaxX(lastLabel.frame) + x * (btnWidth + 12);
        btn.size = CGSizeMake(btnWidth, 25);
        if (labelCount > 3 && i <= 2) {
            btn.bottom = middleHeight - (25 + 14);
        }else{
            btn.bottom = middleHeight;
        }
        btn.layer.cornerRadius = 10;
        btn.layer.masksToBounds = YES;
        [btn setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#D8D8D8" alpha:0.14]] forState:UIControlStateNormal];
        btn.layer.cornerRadius = 12;
        btn.layer.masksToBounds = YES;
        [btn setTitle:labelStr forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.middleBackView addSubview:btn];
    }
    
    self.contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 0, SCREEN_WIDTH - 40, CGRectGetMinY(fjLabel.frame) - 20)];
    
    
    self.contentTextView.backgroundColor = [UIColor clearColor];
    [self.middleBackView addSubview:self.contentTextView];
    self.contentTextView.editable = NO;
    if (self.currentModel.introduce) {
        NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[self.currentModel.introduce dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                                                                                                                                                                 NSFontAttributeName: [UIFont systemFontOfSize:18]
                                                                                                                                                                              } documentAttributes:nil error:nil];
        [attrStr enumerateAttribute:NSFontAttributeName
                                     inRange:NSMakeRange(0, attrStr.string.length)
                                     options:(NSAttributedStringEnumerationReverse) usingBlock:^(UIFont *value, NSRange range, BOOL * _Nonnull stop){
                                         if (value) {
                                             *stop = YES;
                                             [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:range];
                                             
                                         }else{
                                             [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:range];
                                         }
        }];
        self.contentTextView.attributedText = attrStr;
        
        
        UITextView *textv = [[UITextView alloc]initWithFrame:self.contentTextView.frame];
        [self.middleBackView addSubview:textv];
        textv.backgroundColor = [UIColor clearColor];
        textv.editable = NO;
        textv.attributedText = attrStr;
    }
    
    
//    self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(tipWidth+wid(25),height,SCREEN_WIDTH-wid(25)-tipWidth,tipHeight)];
//    [self.middleBackView addSubview:self.scrollView];
//    self.middleBackView.frame = CGRectMake(0,CGRectGetMaxY(self.titleLabelView.frame) + 20,SCREEN_WIDTH, lableMaxY -  CGRectGetMinY(self.contentTextView.frame));
  
}
//播放进度
- (void)setPlayProgress{
    _progressOprateView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.middleBackView.frame) + widScale(30), SCREEN_WIDTH, 65)];
//    _progressOprateView.backgroundColor = [UIColor blueColor];
    [self.view addSubview: _progressOprateView];
    UIButton* houtuiBtn = [UIButton new];
    houtuiBtn.size = CGSizeMake(30, 30);
    houtuiBtn.left = 30;
    houtuiBtn.top = 15;
    houtuiBtn.tag=999;
    [houtuiBtn addTarget:self action:@selector(seekForwardPlayer:) forControlEvents:UIControlEventTouchUpInside];
    [houtuiBtn setBackgroundImage:[UIImage imageNamed:@"后退10秒"] forState:UIControlStateNormal];

    [_progressOprateView addSubview:houtuiBtn];

    UIButton* qianjinBtn = [UIButton new];
    qianjinBtn.tag=1000;
    qianjinBtn.size = CGSizeMake(30, 30);
    qianjinBtn.right = SCREEN_WIDTH - 30;
    qianjinBtn.top = 15;
    [qianjinBtn addTarget:self action:@selector(seekForwardPlayer:) forControlEvents:UIControlEventTouchUpInside];
    [qianjinBtn setBackgroundImage:[UIImage imageNamed:@"前进10秒"] forState:UIControlStateNormal];
    [_progressOprateView addSubview:qianjinBtn];
    [_progressOprateView addSubview:self.sliderView];
//    [_progressOprateView addSubview:self.bigSliderView];

    _sliderView.left = 72;
    _sliderView.width = SCREEN_WIDTH - 144;
    _sliderView.height = 7;
    _sliderView.centerY = qianjinBtn.centerY;
    
    _videoTimeLabel = [UILabel new];
    _videoTimeLabel.size = CGSizeMake(SCREEN_WIDTH, 20);
    _videoTimeLabel.left = 0;
    _videoTimeLabel.bottom = _sliderView.top - 10;
    _videoTimeLabel.text = @"00:00/00:00";
    _videoTimeLabel.textAlignment =  NSTextAlignmentCenter;
    _videoTimeLabel.font = TitleFontSize(16);
    _videoTimeLabel.textColor = UIColor.whiteColor;
    _videoTimeLabel.hidden = YES;
    [_progressOprateView addSubview:_videoTimeLabel];

    _beginTime = [UILabel new];
    _beginTime.left = _sliderView.left;
    _beginTime.top = CGRectGetMaxY(qianjinBtn.frame);
    _beginTime.size = CGSizeMake(80, 14);
    _beginTime.text = @"00:00";
    _beginTime.font = TitleFontSize(12);
    _beginTime.textColor = UIColor.whiteColor;
    [_progressOprateView addSubview:_beginTime];
    [Common updataTimerLableWithLable:_beginTime Second:_currentProgress];

    _endTime = [UILabel new];
    _endTime.left = _sliderView.right - 80;
    _endTime.top = CGRectGetMaxY(qianjinBtn.frame);
    _endTime.size = CGSizeMake(80, 14);
    _endTime.textAlignment = NSTextAlignmentRight;
    _endTime.text = @"00:00";
    _endTime.font = TitleFontSize(12);
    _endTime.textColor = UIColor.whiteColor;
    [_progressOprateView addSubview:_endTime];
    [Common updataTimerLableWithLable:_endTime Second:_currentModel.audioLength];
}
//底部播放view
- (void)initBottomFactView{
    _bottomOprateView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_progressOprateView.frame), SCREEN_WIDTH, 206 + HY_BottomWhiteBar_Height)];
    [self.view addSubview:_bottomOprateView];
    
    UIImageView *playBackView = [[UIImageView alloc] init];
    playBackView.image = IMAGE(@"icon_playbg");
    playBackView.size = CGSizeMake(90, 90);
    playBackView.top = 15;
    playBackView.centerX = SCREEN_WIDTH / 2;
    self.playBackImgV = playBackView;
    [_bottomOprateView addSubview:playBackView];
    
    _playBtn = [UIButton new];
    _playBtn.size = CGSizeMake(56, 56);
    _playBtn.top = 17 + 15;
    _playBtn.centerX = SCREEN_WIDTH / 2;
    [_playBtn setImage:IMAGE(@"icon_stopImg") forState:UIControlStateNormal];
    [_playBtn setImage:IMAGE(@"icon_playImg") forState:UIControlStateSelected];
    
    [_playBtn addTarget:self action:@selector(_playBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    _playBtn.selected = !_isPlaying;
    _playBtn.showsTouchWhenHighlighted = YES;
    [_bottomOprateView addSubview:_playBtn];
    
    _formerBtn = [UIButton new];
    _formerBtn.size = CGSizeMake(30, 30);
    _formerBtn.right = playBackView.left - 20;
    _formerBtn.centerY = playBackView.centerY;
    [_formerBtn setBackgroundImage:IMAGE(@"上一首") forState:UIControlStateNormal];
    
    _formerBtn.imageView.contentMode = UIViewContentModeScaleToFill;
    [_formerBtn setBackgroundImage:IMAGE(@"fullView_playBtn_left_f") forState:UIControlStateDisabled];
    [_formerBtn addTarget:self action:@selector(_formerBtnAction) forControlEvents:UIControlEventTouchUpInside];
    if (_isFirstMusic) _formerBtn.enabled = NO;
    [_bottomOprateView addSubview:_formerBtn];
    
    _nextBtn = [UIButton new];
    _nextBtn.size = CGSizeMake(30, 30);
    _nextBtn.left = playBackView.right + 20;
    _nextBtn.centerY = playBackView.centerY;
    [_nextBtn setBackgroundImage:IMAGE(@"下一首") forState:UIControlStateNormal];
    [_nextBtn setBackgroundImage:IMAGE(@"fullView_playBtn_right_f") forState:UIControlStateDisabled];
        [_nextBtn addTarget:self action:@selector(_nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
    if (_isLastMusic) _nextBtn.enabled = NO;
    [_bottomOprateView addSubview:_nextBtn];
    
    NSArray* iconImage=@[@"循环播放",@"定时器关闭",@"倍速1.0",@"目录"];
    for (NSInteger i = 0; i < iconImage.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        CGFloat buttonW = 30;
        CGFloat spac = (SCREEN_WIDTH - 80 - buttonW * 4) / 3;
        button.left = 40 + i * (30 + spac);
        button.top = self.bottomOprateView.height - 60 - HY_BottomWhiteBar_Height;
        button.width = button.height = 30;
        button.tag = 100 + i;
        [button setBackgroundImage:[UIImage imageNamed:iconImage[i]] forState:UIControlStateNormal];
        button.tag=400+i;
        if (i==1) {
            self.timeBtn = button;
            NSString *timeS = _clockTime > 0 ? [Common updataTimerLableWithSecond:_clockTime] : @"不开启";
            
            [self.countDownView setCountTime:timeS];
            [_timeBtn addTarget:self action:@selector(timeBtnAction) forControlEvents:UIControlEventTouchUpInside];
        }else{
            [button addTarget:self action:@selector(bottomBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        [_bottomOprateView addSubview:button];
    }
    
}
- (void)upDataView{
    [self setTopTabbarView];
    self.titleLabelView.text = self.currentModel.name;
    [self initMiddleTextView];
}
#pragma mark - ZFSliderViewDelegate
- (void)blowUpdataSlider{
    self.sliderView.isdragging = YES;
    self.videoTimeLabel.hidden = NO;
    self.sliderView.sliderHeight = 12;
    self.sliderView.sliderRadius = 6;
    self.middleBackView.hidden = YES;
    self.beginTime.hidden = YES;
    self.endTime.hidden = YES;
    [_sliderView.sliderBtn setImage:[UIImage imageNamed:@"big_Slier"] forState:UIControlStateNormal];

}
- (void)zoomSliderUI{
    self.videoTimeLabel.hidden = YES;
    self.sliderView.sliderHeight = 4;
    self.sliderView.sliderRadius = 2;
    self.beginTime.hidden = NO;
    self.middleBackView.hidden = NO;
    self.endTime.hidden = NO;
    [_sliderView.sliderBtn setImage:[UIImage imageNamed:@"icon_slidBtn"] forState:UIControlStateNormal];

}
- (void)sliderTouchBegan:(float)value {
    NSLog(@"sliderTouchBegan %f", value);
    [self blowUpdataSlider];
}

- (void)sliderTouchEnded:(float)value {
    NSLog(@"sliderTouchEnded %f", value);
    NSTimeInterval currentTime = (NSTimeInterval)(value * self.currentModel.audioLength);
    NSLog(@"sliderTouchEnded  currentTime %f", currentTime);
    [self zoomSliderUI];
//    [[ICMusicPlayManager sharedManager].currentMusicPlayer play];
    //滑动进度条暂停
    if (currentTime > self.currentProgress) {
        slideStatue = MoveForward;
    }else {
        slideStatue = MoveBack;
    }
    self.currentProgress = currentTime;
    if (self.seekProgress) self.seekProgress(currentTime);
    [[ICMusicPlayManager sharedManager] seekToTime:currentTime completionHandler:^(BOOL finished) {
            self.sliderView.isdragging = NO;
            //设置完进度后更新时间
            if(self.selectTimeZone != SelectTimeZoneTwo) [self computationTimeDisplayTimeLableWithSelectZone:self.selectTimeZone NewModel:self.currentModel];
        }];

}

- (void)sliderValueChanged:(float)value {
    NSLog(@"sliderValueChanged %f", value);
    NSTimeInterval currentTime = (NSTimeInterval)(value * self.currentModel.audioLength);
    NSLog(@"sliderValueChanged  currentTime %f", currentTime);
    [Common updataTimerLableWithLable:_beginTime Second:currentTime];
    self.videoTimeLabel.text = [NSString stringWithFormat:@"%@/%@", _beginTime.text, _endTime.text];
}

- (void)sliderTapped:(float)value {
    NSLog(@"sliderTapped %f", value);
    self.sliderView.isdragging = YES;
    NSTimeInterval currentTime = (NSTimeInterval)(value * self.currentModel.audioLength);
    NSLog(@"sliderTapped  currentTime %f", currentTime);
    self.videoTimeLabel.hidden = YES;
    //滑动进度条暂停
    if (currentTime > self.currentProgress) {
        slideStatue = MoveForward;
    }else {
        slideStatue = MoveBack;
    }
    self.currentProgress = currentTime;
    [[ICMusicPlayManager sharedManager] seekToTime:currentTime completionHandler:^(BOOL finished) {
            self.sliderView.isdragging = NO;
            //设置完进度后更新时间
        if(self.selectTimeZone != SelectTimeZoneTwo) [self computationTimeDisplayTimeLableWithSelectZone:self.selectTimeZone NewModel:self.currentModel];
        }];
}

#pragma mark - private method
-(void)getDataWithID:(NSString *)idStr
{
    /**取消掉*/
//    [_objectAFN cancelRequest];
    NSLog(@"idStr----%@", idStr);
    [self.objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/index/Directory?id=%@",server_addr,idStr] finish:^(id  _Nonnull dataString) {
        
        NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",dic);
        self.audioListArray = dic[@"data"][@"data"];
        NSMutableArray *mutArray = [NSMutableArray array];
        for (NSDictionary *dict in self.audioListArray) {
            NSString *videoUrl =  [dict[@"audio_url"] copy];
            if (videoUrl.length > 0) {
                [mutArray addObject:dict];
            }
        }
        self.audioListArray = [NSArray arrayWithArray:mutArray];
    } andError:^(NSError * _Nonnull error) {
        
    }];
}
-(void)getonecollectAction:(NSString *)idStr
{
    /**取消掉*/
//    [_objectAFN cancelRequest];
    NSLog(@"idStr----%@, user_id---%@", idStr, [Cache shared].userInfo.userinfo.user_id);
    [self.objectAFN postUrlStr:[NSString stringWithFormat:@"%@/api/collect/getonecollect",server_addr] parames:@{
        @"media_id": self.currentModel.id ?: @"",
        @"user_id":  idStr ?: @""
    } finish:^(id  _Nonnull dataString) {
        NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
        BOOL type = [dic[@"status"] boolValue];
        self.likeBtn.selected = type;

    } andError:^(NSError * _Nonnull error) {
        
    }];
}
- (void)likeBtnClick:(UIButton *)button{
    /**取消掉*/
//    [_objectAFN cancelRequest];
    [self.objectAFN postUrlStr:[NSString stringWithFormat:@"%@/api/collect/setCollect",server_addr] parames:@{
        @"media_id": self.currentModel.id ?: @"",
        @"user_id":  [Cache shared].userInfo.userinfo.user_id ?: @""
    } finish:^(id  _Nonnull dataString) {
        
        NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
        BOOL type = [dic[@"data"][@"type"] boolValue];
        self.likeBtn.selected = type;
        
    } andError:^(NSError * _Nonnull error) {
        
    }];

}
- (void)tabbarButtonClick:(UIButton *)button{
   
    if (self.videoBtn != button) {
        self.playsubtitleView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabelView.frame) + 20, SCREEN_WIDTH, SCREEN_HEIGHT - (CGRectGetMaxY(self.titleLabelView.frame) + 20) - 68 - HY_BottomWhiteBar_Height);
        self.playsubtitleView.hidden = YES;
        self.bottomOprateView.hidden = NO;
        self.middleBackView.hidden = NO;
        self.progressOprateView.top = CGRectGetMaxY(self.middleBackView.frame) + 30;
        self.tabLineView.centerX  = button.centerX + 77;
        for (UIButton *button in self.stackView.arrangedSubviews) {
            [button setTitleColor:[UIColor colorWithHex:@"#BBC4DA"] forState:UIControlStateNormal];
        }
        [button setTitleColor:[UIColor colorWithHex:@"#FFFFFF"] forState:UIControlStateNormal];
        if (button == self.contentBtn) {
            self.contentTextView.hidden = NO;
        }else if (button == self.audioBtn){
            self.contentTextView.hidden = YES;
        }else if (button == self.zimuBtn){
            self.playsubtitleView.hidden = NO;
            self.playsubtitleView.frame = CGRectMake(0, CGRectGetMaxY(self.titleLabelView.frame) + 20, SCREEN_WIDTH, SCREEN_HEIGHT - (CGRectGetMaxY(self.titleLabelView.frame) + 20) - 68 - HY_BottomWhiteBar_Height);
            [self.playsubtitleView refreshUI:self.playsubtitleView.bounds];
            self.bottomOprateView.hidden = YES;
            self.middleBackView.hidden = YES;
            self.progressOprateView.top = CGRectGetMaxY(self.playsubtitleView.frame);
        }
    }else{
        
        self.contentTextView.hidden = YES;
        HSVideoPlayViewController *vc = [HSVideoPlayViewController new];
        vc.currentModel = self.currentModel;
        _playBtn.selected = YES;
        _isPlaying = YES;
        if (self.playBtnAction) self.playBtnAction(YES);
        [self.navigationController pushViewController:vc animated:YES];
    }
   
}
-(void)bottomBtnAction:(UIButton*)sender
{
    if(sender.tag==400)
    {
        [[PlayModel sharedModel] changePlayStyle];
        NSArray* user = @[@"循环播放",@"单曲播放",@"随机播放"];
//        [sender setTitle:user[[PlayModel sharedModel].playStyle] forState:UIControlStateNormal];
        [sender setBackgroundImage:IMAGE(user[[PlayModel sharedModel].playStyle]) forState:UIControlStateNormal];
        
    }else if(sender.tag==401)/**定时器*/{
        
    }else if(sender.tag==402)/**倍速*/{
        
        PlayMulitplePopView *view = [[PlayMulitplePopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        view.mulitBlock = ^(NSString * _Nonnull mulit) {
            [ICMusicPlayManager sharedManager].currentMusicPlayer.rate = mulit.floatValue;
            [sender setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@", mulit]] forState:UIControlStateNormal];
        };
        
        [view showIn:self.view currentMulitple:[NSString stringWithFormat:@"%f",[ICMusicPlayManager sharedManager].currentMusicPlayer.rate]];
    }else{
        self.listView  = [[PlayListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
       
        UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
        if (!superView) {
            superView = [UIApplication sharedApplication].keyWindow;
        }
        
        [self.listView showIn:self.view listArray:self.audioListArray IdStr:self.currentModel.id];
        
        NSArray *titleArray = [self.currentModel.media_class_name componentsSeparatedByString:@"|"];
        if (titleArray.count >= 2) {
            
            self.listView.subTitleStr = titleArray[1];
        }
        
    }
}

/**快进, 快退*/
-(void)seekForwardPlayer:(UIButton*)sender
{
    CGFloat value=0.0;
    if(sender.tag==1000)
    {
       value=self.currentProgress+10;
    }else
    {
        value=self.currentProgress-10;
    }
    if(value<0)
    {
        value=0.0;
    }else if(value>self.currentModel.audioLength)
    {
        value=self.currentModel.audioLength;
    }
    self.sliderView.value =  value / self.currentModel.audioLength;
    [self sliderTouchEnded:value / self.currentModel.audioLength];
}


- (void)_leftBtnAction{
   
    if (self.progressTimer != nil) {
        [self.progressTimer invalidate];
        self.progressTimer = nil;
    }
    //传出数据
    if (self.closeBtnAction) self.closeBtnAction(_currentModel,_clockTime, _currentSelectTimeIndex,_isPlaying);
//    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)_playListBtnAction {
    //弹出列表
    ICMusicPlayListVC *plistVC = [ICMusicPlayListVC new];
    plistVC.allListModelArray = self.musicArray;
    plistVC.currentModel = self.currentModel;
    plistVC.isPlaying = self.isPlaying;
    @weakify(self)
    plistVC.readPlayMusic = ^(NSInteger currentSelectTimeListIndex, ICMusicPlayModel *model) {
        @strongify(self)
        if(self.readPlayMusic)self.readPlayMusic(currentSelectTimeListIndex, model);
    };
    [self.navigationController pushViewController:plistVC animated:YES];
}
- (void)timeBtnAction {
    //弹出时间列表
    PlayCountDownView *view = [[PlayCountDownView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.countDownView = view;
    view.mulitStr = self.countDownType;
    view.countDownIndexBlock = ^(NSInteger index) {
        [self timeBtnSelectAction:index];
        self.countDownType = self->_timeListNameArray[index];
        [self timeListMaskViewTapAction];
    };
    view.dataSource = _timeListNameArray;
    UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
    if (!superView) {
        superView = [UIApplication sharedApplication].keyWindow;
    }
    [view showIn:self.view muliter:self.countDownType];
//    _timeListMaskView.hidden = NO;
//    for (NSInteger i = 0; i < _timeImageViewArray.count; i++) {
//        UIImageView *imageView = _timeImageViewArray[i];
//        imageView.hidden = (i == _currentSelectTimeIndex) ? NO : YES;
//        UIButton *button = _timeButtonArray[i];
//        if (i == 0) {
//            button.selected = NO;
//        }else {
//            if (i == _timeListNameArray.count - 1) {
//                button.selected = YES;
//            }else {
//                button.selected = (i == _currentSelectTimeIndex) ? YES : NO;
//            }
//        }
//    }
//    _oldSelectTimeIndex = _currentSelectTimeIndex;
//    [UIView animateWithDuration:0.3 animations:^{
//        self->_timeSelectView.top = XHScreenHeight - 445 - SafeAreaBottomHeight;
//    }];
}
- (void)_playBtnAction:(UIButton *)button {
    //播放、暂停
    button.selected = !button.selected;
    _isPlaying = !button.selected;
    if (self.playBtnAction) self.playBtnAction(button.selected);
}

- (void)_formerBtnAction {
    //上一曲,先处理定时
    self.currentProgress = 0;
    if(self.formerBtnAction) self.formerBtnAction(self.currentSelectTimeIndex);
}

- (void)_nextBtnAction {
    //下一曲,先处理定时
    self.currentProgress = 0;
    if (self.nextBtnAction) self.nextBtnAction(self.currentSelectTimeIndex);
}

#pragma mark - 选择定时时间
//- (void)initTimeView {
//    _oldSelectTimeIndex = _currentSelectTimeIndex;
//    _timeListMaskView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, XHScreenWidth, XHScreenHeight)];
//    _timeListMaskView.alpha = 0.5;
//    _timeListMaskView.backgroundColor = XHUIColorFromRGB(0x000000);
//    _timeListMaskView.hidden = YES;
//    UITapGestureRecognizer *timeListMaskViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(timeListMaskViewTapAction)];
//    [_timeListMaskView addGestureRecognizer:timeListMaskViewTap];
//    [self.view addSubview:_timeListMaskView];
//
//    _timeSelectView = [[UIView alloc]initWithFrame:CGRectMake(0, XHScreenHeight, XHScreenWidth, 445 + SafeAreaBottomHeight)];
//    _timeSelectView.backgroundColor = XHAPPSeparateColor;
//    for (NSInteger i = 0; i < _timeListNameArray.count; i++) {
//        UIButton *btn = [UIButton new];
//        [btn setTitle:_timeListNameArray[i] forState:UIControlStateNormal];
//        [btn setTitleColor:XHAPPTitleColor forState:UIControlStateNormal];
//        [btn setTitleColor:XHAPPMainColor forState:UIControlStateSelected];
//        btn.tag = 100 + i;
//        btn.layer.borderWidth = 0.5;
//        btn.layer.borderColor = XHAPPBGColor.CGColor;
//        btn.layer.masksToBounds = YES;
//        btn.backgroundColor = [UIColor whiteColor];
//        [btn addTarget:self action:@selector(timeBtnSelectAction:) forControlEvents:UIControlEventTouchUpInside];
//        [_timeSelectView addSubview:btn];
//        [_timeButtonArray addObject:btn];
//
//        UIImageView *imageView = [UIImageView new];
//        imageView.image = IMAGE(@"icon_check_h");
//        imageView.hidden = (i == _currentSelectTimeIndex) ? NO : YES;
//        [btn addSubview:imageView];
//        [_timeImageViewArray addObject:imageView];
//
//        if (i == 0) {
//            btn.frame = CGRectMake(0, 0, XHScreenWidth, 44);
//            [btn setTitleColor:XHAPPSubheadColor forState:UIControlStateNormal];
//            btn.titleLabel.font = FONT(14);
//            imageView.frame = CGRectMake(XHScreenWidth - 15 - 22, 11 , 22, 22);
//        }else {
//            if (i == _timeListNameArray.count - 1) {
//                btn.frame = CGRectMake(0, 445 - 50 , XHScreenWidth, 50 + SafeAreaBottomHeight);
//                btn.selected = YES;
//            }else {
//                btn.frame = CGRectMake(0, 44 + (i - 1) * 49, XHScreenWidth, 49);
//                imageView.frame = CGRectMake(XHScreenWidth - 15 - 22, 13.5 , 22, 22);
//                btn.selected = (i == _currentSelectTimeIndex) ? YES : NO;
//            }
//        }
//    }
//    [self.view addSubview:_timeSelectView];
//}
- (void)timeBtnSelectAction:(NSInteger)index {
    [self selectClockTimeWithIndex:index];
}
//时间选中后的实现
- (void)timeListMaskViewTapAction {
    _timeListMaskView.hidden = YES;
    [UIView animateWithDuration:0.3 animations:^{
        self->_timeSelectView.top = XHScreenHeight;
    }completion:^(BOOL finished) {
        //开始计时
        if(self->_oldSelectTimeIndex == self->_currentSelectTimeIndex)return;
        [self computationTimeDisplayTimeLableWithSelectZone:self.selectTimeZone NewModel:self.currentModel];
    }];
}

- (void)updataTimeShowWithCurrentTime:(NSInteger)time {
    if (time == 0) {
//        [_timeBtn setTitle:@"定时关闭" forState:UIControlStateNormal];
        [self.countDownView setCountTime:@"定时关闭"];
    }else {
        NSString *timertitle = [Common updataTimerLableWithSecond:time];
//        [_timeBtn setTitle:timertitle forState:UIControlStateNormal];
        [self.countDownView setCountTime:timertitle];
    }
}
#pragma mark - private
- (void)computationTimeDisplayTimeLableWithSelectZone:(SelectTimeZone)zone NewModel:(ICMusicPlayModel *)model{
    //计算时间
    self.clockTime = (zone == SelectTimeZoneNone) ? 0 : [self totleTimeClockWithIndex:_currentSelectTimeIndex CurrentModel:model ModelArray:self.musicArray];
 if(self.currentClockTime) self.currentClockTime(self.clockTime,zone,self.currentSelectTimeIndex);
}
//@[@"不开启",@"10分钟后",@"20分钟后",@"30分钟后",@"60分钟后",@"90分钟后",@"播完当前音频后"]
- (void)selectClockTimeWithIndex:(NSInteger)index{
    if (index == 0) {
        self.selectTimeZone = SelectTimeZoneNone;
    }else if (1 <= index && index <= 5) {
        self.selectTimeZone = SelectTimeZoneTwo;
    }else if (index == 6) {
        self.selectTimeZone = SelectTimeZoneOne;
    }
//    //其他
//    for (NSInteger i = 1; i < _timeListNameArray.count; i++) {
//        UIButton *btn = _timeButtonArray[i];
//        UIImageView *imageView = _timeImageViewArray[i];
//        btn.selected = i == index ? YES : NO;
//        imageView.hidden = i == index ? NO : YES;
//    }
    //记录选项
    _currentSelectTimeIndex = index;
}

- (void)updateTimeShow {
    NSString *timertitle = [Common updataTimerLableWithSecond:_clockTime];
//    [_timeBtn setTitle:timertitle forState:UIControlStateNormal];
    [self.countDownView setCountTime:timertitle];

//    [_timeBtn layoutButtonWithEdgeInsetsStyle:ICButtonEdgeInsetsStyleTop imageTitleSpace:2];
}

//计算定时
- (NSInteger)totleTimeClockWithIndex:(NSInteger)index CurrentModel:(ICMusicPlayModel *)model ModelArray:(NSArray *)musicArray{
    if (index < 1 || index > 7) return 0;
   __block NSInteger clockSum = 0;
    if (index > 1 && index < 5) {
        //正常播放完成的去除
        NSInteger newIndex = self.overPlayNum > 0 ? (index - self.overPlayNum) : index;
        for (NSInteger i = 0; i < newIndex - 1; i++) {
            CurriculumModel *playModel = musicArray[i];

            [[ICMusicPlayManager sharedManager].oprationPlay getIndexModelWith:model.rownum + i Complete:^(ICMusicPlayModel * _Nonnull model) {
                
                clockSum += model.audioLength;
                //如果是正在播放的歌曲，减去当前播放歌曲的进度
                if([self.currentModel.audio_url isEqualToString: model.audio_url]){
                    clockSum -= self.currentProgress;
                };
            }];
          
        }
    }else if(index == 1){
        clockSum = 0;
    }else {
        clockSum = 600 * (index - 4);
    }
    return clockSum;
}
#pragma mark - getters and setters
#pragma mark - set
- (void)setCurrentModel:(ICMusicPlayModel *)currentModel {
    if (currentModel == nil) return;
    _currentModel  = currentModel;
    //进度条
    [self setTopTabbarView];
    [self initMiddleTextView];
    if (self.listView) {
        [self.view bringSubviewToFront:self.listView];
    }
    self.totleTime = self.currentModel.audioLength;
//    self.sliderView.maximumValue = 1;//音乐总共时长
    [Common updataTimerLableWithLable:_endTime Second:self.currentModel.audioLength];
    
    //上一首，下一首，更新定时显示
    if(self.selectTimeZone != SelectTimeZoneTwo)[self computationTimeDisplayTimeLableWithSelectZone:self.selectTimeZone NewModel:self.currentModel];
}

- (void)setCurrentProgress:(NSTimeInterval)currentProgress {
    _currentProgress = currentProgress;
    if (!self.sliderView.isdragging) {
        _sliderView.value  = currentProgress / self.currentModel.audioLength;
    }
    [self.playsubtitleView updateProgress];
    [Common updataTimerLableWithLable:_beginTime Second:currentProgress];
}
- (void)setBuffingProgress:(NSTimeInterval)buffingProgress {
    _buffingProgress = buffingProgress;
    _sliderView.bufferValue =  buffingProgress / self.currentModel.audioLength;
}

- (void)setTotleTime:(NSTimeInterval)totleTime {
    _totleTime = totleTime;
    [Common updataTimerLableWithLable:_endTime Second:totleTime];
}
- (void)setIsLastMusic:(BOOL)isLastMusic {
    _isLastMusic = isLastMusic;
    _nextBtn.enabled = !isLastMusic;
}
- (void)setIsFirstMusic:(BOOL)isFirstMusic {
    _isFirstMusic = isFirstMusic;
    _formerBtn.enabled = !isFirstMusic;
}
- (void)setIsPlaying:(BOOL )isPlaying {
    _isPlaying = isPlaying;
    _playBtn.selected = !isPlaying;
}
- (void)setClockTime:(NSInteger)clockTime {
    _clockTime = clockTime;
    //当选择10分钟以上定时，由外部管理定时不需要重新计算
    if (self.currentSelectTimeIndex > 4) return;
    NSString *timeS = _clockTime > 0 ? [Common updataTimerLableWithSecond:_clockTime] : @"定时关闭";
//    [_timeBtn setTitle:timeS forState:UIControlStateNormal];
    [self.countDownView setCountTime:timeS];

//    [self setButtonImage:@"" ButtonTitle:timeS ButtonUI:_timeBtn];
}
#pragma mark - getter
- (UIStackView *)stackView{
    if (!_stackView) {
        _stackView = [[UIStackView alloc] initWithFrame:CGRectMake(77, 83, SCREEN_WIDTH - 154, 22)];
        _stackView.axis = UILayoutConstraintAxisHorizontal;
        _stackView.distribution = UIStackViewDistributionFillEqually;
        _stackView.spacing = 0;
        _stackView.alignment = UIStackViewAlignmentFill;
    }
    return _stackView;
}
- (UIView *)tabLineView{
    if (!_tabLineView) {
        _tabLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, 2)];
        _tabLineView.backgroundColor = [UIColor colorWithHex:@"#0091FF"];
    }
    return _tabLineView;
}
//- (ZFSliderView *)bigSliderView {
//    if (!_bigSliderView) {
//        _bigSliderView = [[ZFSliderView alloc] init];
//        _bigSliderView.delegate = self;
//        _bigSliderView.maximumTrackTintColor = [UIColor colorWithWhite:0 alpha:0.18];
//        _bigSliderView.bufferTrackTintColor  = [UIColor colorWithHex:@"#D8D8D8"];
//        _bigSliderView.minimumTrackTintColor = [UIColor colorWithHex:@"#0091FF"];
//        _bigSliderView.sliderHeight = 12;
//        _bigSliderView.sliderRadius = 6;
//        [_bigSliderView.sliderBtn setImage:[UIImage imageNamed:@"icon_slidBtn"] forState:UIControlStateNormal];
//
//        _bigSliderView.hidden = YES;
//    }
//    return _bigSliderView;
//}
- (ZFSliderView *)sliderView {
    if (!_sliderView) {
        _sliderView = [[ZFSliderView alloc] init];
        _sliderView.delegate = self;
        _sliderView.maximumTrackTintColor = [UIColor colorWithWhite:0 alpha:0.18];
        _sliderView.bufferTrackTintColor  = [UIColor colorWithHex:@"#D8D8D8"];
        _sliderView.minimumTrackTintColor = [UIColor colorWithHex:@"#0091FF"];
        _sliderView.sliderHeight = 4;
        _sliderView.sliderRadius = 2;
        [_sliderView.sliderBtn setImage:[UIImage imageNamed:@"icon_slidBtn"] forState:UIControlStateNormal];
    }
    return _sliderView;
}
-(PlayVoiceSubtitleView*)playsubtitleView
{
    if(!_playsubtitleView)
    {
        _playsubtitleView=[[PlayVoiceSubtitleView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.stackView.frame) + 67, SCREEN_WIDTH, SCREEN_HEIGHT - (CGRectGetMaxY(self.stackView.frame) + 67) - 68 - HY_BottomWhiteBar_Height)];
        _playsubtitleView.hidden = YES;
        
        [self.view addSubview:_playsubtitleView];
    }
    return _playsubtitleView;
}
- (PlayLoadingView *)loadingView{
    if (!_loadingView) {
        _loadingView = [[PlayLoadingView alloc] initWithFrame:CGRectZero];
        [self.playBackImgV addSubview:_loadingView];
        _loadingView.size = CGSizeMake(56, 56);
        _loadingView.centerY = self.playBackImgV.height /  2;
        _loadingView.centerX = self.playBackImgV.width / 2;
        _loadingView.hidden = YES;
    }
    return _loadingView;
}

- (UILabel *)titleLabelView{
    if (!_titleLabelView) {
        _titleLabelView = [self setTextLabel:@"这里显示的是标题" frame:CGRectMake(26,124,170,27) font:[UIFont systemFontOfSize: 20]];
        _titleLabelView.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabelView;
}
- (UIView *)tagView{
    if (!_tagView) {
        _tagView = [[UIView alloc] init];
        _tagView.backgroundColor = [UIColor  colorWithHex:@"#0091FF"];
        _tagView.x = 19;
        _tagView.y = HY_StatusBar_Height + 42;
        _tagView.width = 2;
        _tagView.height = 13;
        [self.view addSubview:_tagView];
    }
    return _tagView;
}

@end
